package zjut.cocouml.command;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;

import zjut.cocouml.model.BCanvas;
import zjut.cocouml.model.BUseCase;


public class BUseCaseCreateCommand extends Command{
	
	private BCanvas canvas;
	private BUseCase model;
	
	public BUseCaseCreateCommand() {
		super();
		canvas = null;
		model = null;
	}
	public void setCanvas(Object canvas) {
		if (canvas instanceof BCanvas) 
			this.canvas = (BCanvas)canvas;
	}
	public void setModel(Object model) {
		if (model instanceof BUseCase)
			this.model = (BUseCase)model;
	}
	
	public void setLayout(Rectangle r) {
		if (model == null)
			return;
		model.setLayout(r);
	}
	public boolean canExecute() {
		if (model == null || canvas == null) 
			return false;
		return true;
	}
	public void execute() {
		canvas.addChild(model);
	}
	
	public boolean canUndo() {
		if (canvas == null || model == null)
			return false;
		return true;
	}
	public void undo() {
		canvas.removeChild(model);
	}	
	
}
